﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;

namespace Kaskelot.Services.Model
{
    public partial class KaskelotEntities
    {
        public override int SaveChanges()
        {
            foreach (DbEntityEntry entry in this.ChangeTracker.Entries())
            {
                var entity = entry.Entity as IEntity;
                if (entity != null)
                {
                    switch (entry.State)
                    {
                        case EntityState.Modified :
                            entity.OnBeforeUpdate();
                            break;
                        case EntityState.Added :
                            entity.OnBeforeCreate(this);
                            break;
                    }
                }
            }
            return base.SaveChanges();
        }
    }
}
